/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author ChauAnh
 */
@Stateless
public class ChangeAvatar implements ChangeAvatarLocal {

    @Override
    public Boolean updateAvatar(String username, String avatar) {
        try {
            ConnectDB conDB = new ConnectDB();
            Connection conn = conDB.getConnection();
            String strSql = "UPDATE candidate SET avatar = ? WHERE username = ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, avatar);
            pstmt.setString(2, username);            
            int update = pstmt.executeUpdate();
            if (update==1) {           
                return true;
            }
            conn.close();

        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

}
